package com.heima.admin.controller.v1;

import com.heima.admin.service.AdSensitiveService;
import com.heima.apis.admin.AdSensitiveControllerApi;
import com.heima.model.admin.dtos.AdSensitiveDto;
import com.heima.model.admin.pojos.AdSensitive;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/sensitive")
@Api(tags = "敏感词管理")
public class AdSensitiveController  implements AdSensitiveControllerApi {

    //注入service层对象
    @Autowired
    private AdSensitiveService sensitiveService;

    @PostMapping("/list")
    @Override
    @ApiOperation(value = "分页查询敏感词")
    public ResponseResult findByNameAndPage(@RequestBody AdSensitiveDto dto) {
        return sensitiveService.findByNameAndPage(dto);
    }

    //新增敏感词方法
    @Override
    @PostMapping("/save")
    @ApiOperation(value = "添加敏感词")
    public ResponseResult save(@RequestBody AdSensitive sensitive) {
        return sensitiveService.insert(sensitive);
    }


    //新增敏感词方法
    @Override
    @PostMapping("/update")
    @ApiOperation(value = "修改敏感词")
    public ResponseResult update(@RequestBody AdSensitive sensitive) {
        System.out.println(sensitive);
        return sensitiveService.update(sensitive);
    }

    //新增敏感词方法
    @Override
    @PostMapping("/delete/{id}")
    @ApiOperation(value = "物理删除敏感词")
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
        System.out.println("要删除 敏感词的 id 为:"+id);
        return sensitiveService.deleteById(id);
    }
}
